<template>
	<view class="wanlshop-classify-container">
		<view class="wanlshop-classify-container__list">
			<scroll-view scroll-y scroll-with-animation class="left" :scroll-top="scrollTop"
				:style="{ height: `${mainHeight}px` }">
				<view v-for="(item,index) in categoryData" :key="item.id" class="item"
					:class="[currentTab == index ? 'active' : '']" :data-current="index" @tap.stop="handleNav">
					<text>{{ item.shopname }}</text>
				</view>
			</scroll-view>
			<block v-for="(item,index) in categoryData" :key="item.id">
				<scroll-view scroll-y class="right" :style="{ height: `${mainHeight}px` }" v-if="currentTab == index">
					<view class="list-cat">
						<view class="padding-top-sm">
							<view class="list-item radius-bock">
								<view class="list-container">
									<view class="list-box" v-for="(goods, infokey) in item.childlist" :key="goods.id"
										@tap="handleProduct(goods.id, goods.name)">
										<image lazy-load :src="$wanlshop.oss(goods.image, 60, 60)" class="list-image" />
										<view class="text-sm">{{ goods.title }}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'wanlShopClassify',
		props: {
			shopId: {
				type: Number,
				default: 0
			},
			mainHeight: {
				type: Number,
				default: 0
			},
			adverData: {
				type: Object,
				default () {}
			},
			categoryData: {
				type: Array,
				default: () => {
					return []
				}
			}
		},
		data() {
			return {
				currentTab: 0, //预设当前项的值
				scrollTop: 0, //tab标题的滚动条位置
			}
		},
		mounted() {
			console.log('-==--=list', this.categoryData)
		},
		methods: {
			// 点击标题切换当前页时改变样式
			handleNav(e) {
				let cur = e.currentTarget.dataset.current;
				if (this.currentTab == cur) {
					return false;
				} else {
					this.currentTab = cur;
					this.checkCor();
				}
			},
			handleProduct(goods_id) {
				this.$wanlshop.to(
					'/pages/product/goods?id=' + goods_id
				)
			},
			//判断当前滚动超过一屏时，设置tab标题滚动条。
			checkCor() {
				if (this.currentTab > 7) {
					this.scrollTop = 500;
				} else {
					this.scrollTop = 0;
				}
			}
		}
	}
</script>

<style lang="scss">
	.text-sm{
		  overflow: hidden;
		  text-overflow: ellipsis;
		  display: -webkit-box;
		  -webkit-line-clamp: 2;
		  -webkit-box-orient: vertical;
	}
	.wanlshop-classify-container {
		&__one {
			padding-left: 25rpx;
			padding-right: 25rpx;
			padding-bottom: 100rpx;
			padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);

			image {
				width: 100%;
				height: 300rpx;
				border-radius: 15rpx;
				overflow: hidden;
			}

			.item {
				position: relative;
				display: flex;
				justify-content: center;
				margin-top: 25rpx;

				.category-title {
					font-size: 26rpx;
					position: absolute;
					bottom: 20rpx;
					border-radius: 10rpx;
					overflow: hidden;
					color: #666666;
					background-color: rgba(255, 255, 255, .6);
					width: 60%;
					text-align: center;
					padding: 4rpx 0;
				}
			}
		}

		&__grid {
			padding-bottom: 100rpx;
			padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);

			.cu-list {
				background-color: rgba(255, 255, 255, 0);

				&>.cu-item {
					padding: 25rpx 0;
					align-items: center;

					image {
						width: 160rpx;
						height: 160rpx;
						margin-bottom: 10rpx;
					}
				}
			}
		}

		&__list {
			display: flex;

			.left {
				width: 200rpx;
				z-index: 10;
				background: #fbfbfb;

				.item {
					width: 200rpx;
					height: 110rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 26rpx;
					color: #444;
					font-weight: 400;

					&.active {
						position: relative;
						color: #000;
						font-size: 30rpx;
						font-weight: 600;
						background: white;

						&::before {
							content: '';
							position: absolute;
							border-left: 6rpx solid #fe6600;
							height: 32rpx;
							left: 0;
						}
					}
				}
			}

			.right {
				width: 100%;
				padding-left: 25rpx;
				box-sizing: border-box;

				/* background-image: linear-gradient(#fff, #f2f2f2, #f4f4f4, #f6f6f6); */
				.list-cat {
					width: 100%;
					overflow: hidden;
					padding-top: 10rpx;
					padding-right: 20rpx;
					box-sizing: border-box;
				}

				.screen-swiper {
					min-height: 180rpx;
					height: 180rpx;
					overflow: hidden;
				}

				.list-item {
					background: #ffffff;
					width: 100%;
					box-sizing: border-box;
					padding: 20rpx;
					margin-bottom: 20rpx;

					.title {
						color: #FF4F00;
					}
				}

				.list-container {
					/* padding-top: 20rpx; */
					display: flex;
					display: -webkit-flex;
					justify-content: flex-start;
					flex-direction: row;
					flex-wrap: wrap;
				}

				.list-box {
					width: 33.3333%;
					text-align: center;
					padding-top: 40rpx;
				}

				.list-image {
					width: 120rpx;
					height: 120rpx;
				}
			}
		}
	}
</style>